package d1_com.itheima.file;

import java.io.File;
import java.io.IOException;
import java.util.Arrays;

public class Test2 {
    public static void main(String[] args) throws IOException {
        File f1 = new File("C:/Users/23738/Downloads/2.txt");
        System.out.println(f1.createNewFile());//创建文件

        File f2 = new File("C:/Users/23738/Downloads/2");
        System.out.println(f2.mkdir());//创建一级文件夹

        File f3 = new File("C:/Users/23738/Downloads/3/3/3/3");
        System.out.println(f3.mkdirs());//创建多级文件夹

        System.out.println(f1.delete());//只能删除文件和空文件夹
        System.out.println(f2.delete());//只能删除文件和空文件夹

        //遍历文件夹
        File f4 = new File("C:/Users/23738/Downloads/临时图片");
        String[] list = f4.list();
        for (String s : list) {
            System.out.println(s); //遍历文件夹的信息
        }

        //获取当前目录下所有的”一级文件对象到File数组中“
        File[] files = f4.listFiles();
        for (File file : files) {
            System.out.println(file.getAbsolutePath());
        }
    }
}
